﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

namespace pcsse.activity
{
    public partial class manageactivity : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["Priority"] != null)
            {
                int pri = Convert.ToInt32(Session["Priority"].ToString());
                //这里只允许权限为总支书的党员审批活动，党员权限在表T_PRIORITY中给出
                if (pri < 4)
                {
                    Response.Redirect("~/default.aspx");
                }
                mGvOds.FilterExpression = "STATE < 2";
            }
            errLb.Text = "";
        }

        protected void mainGv_PreRender(object sender, EventArgs e)
        {

        }

        protected void mainGv_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label lb = (Label)e.Row.FindControl("stateLb");
                int state = Convert.ToInt32(lb.Text);
                switch (state)
                {
                    case 0:
                        lb.Text = "未审批";
                        break;
                    case 1:
                        lb.Text = "驳回";
                        break;
                    case 2:
                        lb.Text = "通过";
                        break;
                }
            }
        }

        protected void activityDv_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e)
        {
            if (e.Exception != null)
            {
                errLb.Text = e.Exception.ToString();
            }
            else
            {
                mainGv.DataSourceID = "mGvOds";
                mainGv.SelectedIndex = -1;
            }
        }

        protected void activityDv_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
        {
            if (e.NewValues[0] == null || e.NewValues[0].ToString() == "未审批")
            {
                int state = Convert.ToInt32(e.NewValues[1].ToString());
                if (state == 1)
                {
                    errLb.Text = "请务必输入驳回申请的理由！";
                    e.Cancel = true;
                }
                else if(state == 0)
                {
                    e.NewValues[0] = "未审批";
                }else{
                    e.NewValues[0] = "已通过审批";
                }
            }
        }
    }
}
